package com.example.fmgidsprototype;

import java.util.ArrayList;
import java.util.List;

import android.app.IntentService;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.example.fmgidsprototype.data.DataManager;
import com.example.fmgidsprototype.model.Category;
import com.example.fmgidsprototype.model.Venue;

public class VenueDownloader extends IntentService{
	
	private DataManager dm;
	

	public VenueDownloader() {
		super("VenueDownloader");
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onHandleIntent(Intent workIntent) {
		FmGidsPrototypeApp app = (FmGidsPrototypeApp)getApplication();
		dm = app.getDataManager();
		ArrayList<Venue> venues = new ArrayList<Venue>(dm.getAllVenuesWithLocations());
		ArrayList<Category> categories = new ArrayList<Category>(dm.getAllCategories());
		Intent localIntent = new Intent(AppConstants.TRANSACTION_DONE);
		localIntent.putExtra(AppConstants.VENUES_DOWNLOAD, venues);
		localIntent.putExtra(AppConstants.CATS_DOWNLOAD, categories);
		LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
	}

}
